package controleur;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import view.ContactForm;
import view.DeleteForm;
import view.PrincipalWindow;
import view.SearchForm;

public class ActionVue implements ActionListener{
	
	
	private PrincipalWindow view;
	public static ContactForm cont;
	private SearchForm search;
	private DeleteForm del;
	public static JScrollPane sp;
    public static DefaultTableModel table;
    public static boolean checked = false;
    
    /**
	 * @return the table
	 */
	public DefaultTableModel getTable() {
		return table;
	}

	/**
	 * @param table the table to set
	 */
	public void setTable(DefaultTableModel table) {
		this.table = table;
	}

	public static final String cols[] = {"First Name", "Last Name","Group", "Address Home", "Address Company", "Home Phone",
    		"Mobile Phone", "Professional Phone", "Personal Email", "Professional Email", "Web Page", "Picture"};
	
	public ActionVue(PrincipalWindow view){
		this.view = view;
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
		        //fichier = new FichierDroguerie();
		        if (e.getSource() == view.getjButtonAdd()) {
		        	Thread t = new Thread(){
		                public void run() {
		                	cont = new ContactForm();
				            cont.Menu(cols);
				            ActionContact actioncont = new ActionContact(cont);
				            cont.getJButtonValidate().addActionListener(actioncont);
				            cont.getJButtonBrowseIMG().addActionListener(actioncont);
		                }
		            };
		            t.start();

		        } else if (e.getSource() == view.getjButtonDelete()) {
		        	
		        	Thread t = new Thread(){
		                public void run() {
		                	del = new DeleteForm();
				            del.Menu();
				            ActionDelete actiondel = new ActionDelete(del);
				            del.getJButtonValidate().addActionListener(actiondel);
		                }
		            };
		            t.start();
		        	

		        }else if (e.getSource() == view.getjButtonSearch()) {
		        	
		        	Thread t = new Thread(){
		                public void run() {
		                	search = new SearchForm();
				            search.Menu();
				            ActionSearch actionsearch = new ActionSearch(search);
				            search.getJButtonValidate().addActionListener(actionsearch);
		                }
		            };
		            t.start();
		            
		            

		        } else if (e.getSource() == view.getjButtonEdit()) {
		        	
		        	Thread t = new Thread(){
		                public void run() {
		                	search = new SearchForm();
				            search.Menu();
				            ActionEdit actionedit = new ActionEdit(search);
				            search.getJButtonValidate().addActionListener(actionedit);	
		                }
		            };
		            t.start();
		        	         
		        }
	}
}
